<?php
namespace app\api\controller;

use app\api\lists\TaskLists;
use app\api\logic\TaskLogic;
use app\api\validate\TaskValidate;
use app\common\service\WeChatService;

class TaskController extends BaseShopController
{
    public array $notNeedLogin = [];

    public function lists(){
        return $this->dataLists(new TaskLists());
    }

    public function myTaskList(){
        $logic = new TaskLogic();
        return $logic->myTaskList($this->userInfo);        
    }
    /**
     * @notes 添加任务
     * */
    public function add(){
        $params = (new TaskValidate())->post()->goCheck('addTaskBatch', ['user_id' => $this->userId]);
        $logic = new TaskLogic();
        $rs = $logic->addTaskList($params);
        if($rs === false){
            return $this->fail($logic->getError());
        }
        return $this->success('操作成功', $rs);
    }

    public function edit(){
        $task = $this->request->post('task/s');
        $logic = new TaskLogic();
        return $logic->editTask($task,$this->userInfo);
    }

    /**
     * 取消任务
     */
    public function cancel(){
        $params = (new TaskValidate())->post()->goCheck('OpOwner', ['user_id' => $this->userId]);
        $logic = new TaskLogic();
        return $logic->cancelTask($params,$this->userId);
    }

    /**
     * 删除任务
    */
    public function del(){
        $params = (new TaskValidate())->post()->goCheck('OpOwner', ['user_id' => $this->userId]);
        $logic = new TaskLogic();
        $rs = $logic->deleteTask($params,$this->userId);
        if($rs) return $this->success('操作成功');
        return $this->fail($logic->getError());
    }

    public function complete(){
        $params = (new TaskValidate())->post()->goCheck('OpWoker', ['user_id' => $this->userId]);
        $logic = new TaskLogic();
        $logic->completeTask($params);
        return $this->success('操作成功', []);
    }
    /**
     * 开始做任务
     */
    public function start(){
        $params = (new TaskValidate())->post()->goCheck('OpWoker', ['user_id' => $this->userId]);
        $logic = new TaskLogic();
        $logic->workingTask($params);
        return $this->success('操作成功', []);
    }
    /**
     * 确认任务
     */
    public function confirm(){
        $params = (new TaskValidate())->post()->goCheck('OpOwner', ['user_id' => $this->userId]);
        $logic = new TaskLogic();
        return $logic->confirmTask($params,$this->userInfo);
    }

    public function addReward(){
        $task = $this->request->post('task/s');
        $logic = new TaskLogic();
        return $logic->addTaskReward($task,$this->userInfo);
    }

    public function addTaskList(){

    }

    public function share(){
    
    }

    public function temptask(){
        $logic = new TaskLogic();
        return $this->success('操作成功', $logic->temptask($this->userId));
    }

    /**
     * @notes 查询任务
     *
     */
    public function queryTask(){
        $share_code = $this->request->post('share_code');
        $logic = new TaskLogic();
        $rs = $logic->queryTaskList($share_code,$this->userId);
        if($rs) return $this->success('操作成功',$rs);
        return $this->fail($logic->getError());
    }

    /**
     * @notes 加入任务
     *
     */
    public function joinTask(){
        $share_code = $this->request->post('share_code');
        $logic = new TaskLogic();
        $rs = $logic->joinTaskList($share_code,$this->userId);
        if($rs) return $this->success('操作成功',$rs);
        return $this->fail($logic->getError());
    }


    public function workingTask(){
        $logic = new TaskLogic();
        return $this->success('操作成功', $logic->workingTaskList($this->userId));
    }

    public function statistics(){
        
        $logic = new TaskLogic();
        $rs = $logic->myTaskData($this->userId);
        if($rs) return $this->success('操作成功',$rs);
        return $this->fail($logic->getError());
    }

}
